import host from "./config.js"

const BASE_URL = 'https://api-hmugo-web.itheima.net/api/public/v1'

module.exports = {
	request(url,method,data){
		return new Promise((resolve,reject)=>{
			uni.request({
				url: BASE_URL + url,	
				method:method || 'GET',		//使用方式 get或post
				data:data || {},			//数据
				success(res){
					console.log(res)
					if(res.data.meta.status !== 200){
						uni.showToast({
							title:'获取数据失败',
							icon:'error'
						})
					}
					resolve(res)
				},
				fail(err){
					uni.showToast({
						title:'请求接口失败',
						icon:'error'
					})
					reject(err)
				}
			})
		})
	}
}